package com.cloud.lan.entity.base;

import lombok.Data;

import java.io.Serializable;

/**
 * Created by zhouquan on 2022/4/4.
 */
@Data
public class ListResponse<T> implements Serializable {

    public static final String OK = "00000";
    public static final String TOKEN_ERROR = "99991";
    public static final String ERROR = "99999";
    public static final String PARAMS_ILLEGAL = "99998";
    public static final String ERROR_MSG = "系统异常";
    public static final String OK_MSG = "OK";
    private static final long serialVersionUID = 1L;
    private String code; // 默认无异常

    private String msg;

    private T data;

    private int nums;

    public ListResponse() {
        this.code = OK;
        this.msg = OK_MSG;
    }

    public ListResponse(T data) {
        this.code = OK;
        this.msg = OK_MSG;
        this.data = data;
    }

    public static ListResponse error(String code, String msg) {
        ListResponse listResponse = new ListResponse();
        listResponse.code = code;
        listResponse.msg = msg;
        return listResponse;
    }


    public static ListResponse success() {
        ListResponse listResponse = new ListResponse();
        listResponse.code = OK;
        listResponse.msg = OK_MSG;
        return listResponse;
    }

    public static ListResponse success(Object data) {
        ListResponse listResponse = new ListResponse();
        listResponse.code = OK;
        listResponse.msg = OK_MSG;
        listResponse.data = data;
        return listResponse;
    }
}
